package cn.vc.backstage.jobhandler;

import cn.vc.content.entity.article.Article;
import cn.vc.content.entity.video.dto.VideoDto;
import cn.vc.content.feign.clients.article.ArticleClient;
import cn.vc.content.feign.clients.video.VideoClient;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mo
 * @Description: 内容审核
 * @日期: 2024-04-15 23:50
 **/
@Slf4j
@Component
public class ContentAudit {

    @Resource
    private VideoClient videoClient;
    @Autowired
    private ArticleClient articleClient;

    /**
     * 查询需要审核的视频
     */
    @XxlJob("auditVideoJobHandler")
    public void auditVideo() {
        // 查询需要审核的视频
        List<VideoDto> videoDtoList = videoClient.selectDraft();
        if (videoDtoList==null || videoDtoList.isEmpty()) {
            return;
        }
        // 开始审核
        videoDtoList.forEach(videoDto -> {
            log.debug("审核视频：{}", videoDto);
            // 审核通过
            videoClient.passTheAudit(videoDto.getId());
        });
    }

    /**
     * 查询需要审核的文章
     */
    @XxlJob("auditArticleJobHandler")
    public void auditArticle() {
        // 查询需要审核的视频
        List<Article> articleList = articleClient.selectDraft();
        if (articleList==null || articleList.isEmpty()) {
            return;
        }
        // 开始审核
        articleList.forEach(article -> {
            log.debug("审核文章：{}", article);
            // 审核通过
            articleClient.passTheAudit(article.getId());
        });
    }

}
